package FSMDemo.screens
{
	import FSMDemo.entity.Building;
	import FSMDemo.entity.EntityTypes;
	import FSMDemo.entity.Harvester.Harvester;
	import FSMDemo.entity.Harvester.states.WorkState;
	import FSMDemo.entity.mine.Mine;
	
	import com.cheezeworld.AI.Behaviors.Wander;
	import com.cheezeworld.GameFactory;
	import com.cheezeworld.entity.GameWorld;
	import com.cheezeworld.math.Vector2D;
	import com.cheezeworld.screens.AScreen;
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.utils.Input;
	import com.cheezeworld.utils.KeyCode;
	import com.urbansquall.ui.CustomTextField;

	public class DemoScreen extends AScreen
	{
		public function DemoScreen( a_parentScreen:IScreenItem=null )
		{
			super( a_parentScreen );
			// Set up gameworld / factory
			m_factory = new GameFactory();
			EntityTypes.register( m_factory );
			m_gameworld = m_factory.createGameworld( new Vector2D( 2000, 2000 ), new Vector2D( 550, 400 ), this );
			
			
			var ship:Harvester = m_factory.getEntity( "Harvester" );
			ship.newPos.Set( 200, 200 );
			m_gameworld.camera.followPos( ship.actualPos );
			
			var mine:Mine = m_factory.getEntity( "Mine" );
			mine.newPos.Set( 600, 600 );
			
			var base:Building = m_factory.getEntity( "Base" );
			base.newPos.Set( 200, 200 );
			
			m_gameworld.update( 1 ); // Call this so that the entities get added before we set up the states etc.
			ship.FSM.changeState( new WorkState()); 
			ship.steering.addBehavior( new Wander() );
			
			var infotext:CustomTextField = new CustomTextField( "Press <Enter> to restart demo", 0xFFFFFF );
			addChild( infotext );
		}
		
		public override function update(a_timePassed:int):void
		{
			m_gameworld.update( a_timePassed );
			 
			if( Input.instance.isKeyPressed( KeyCode.ENTER ))
			{
				setScreen( DemoScreen );
			}
					
		}
		
		public override function dispose():void
		{
			m_factory.dispose();
			m_gameworld.dispose();
		}
			
		private var m_factory:GameFactory;
		private var m_gameworld:GameWorld;
		
	}
}